from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-02 14:03:53.228168
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 02, Dec, 2021
Time: 14:03:59
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.3141
Nobs: 493.000 HQIC: -47.7799
Log likelihood: 5646.13 FPE: 1.31440e-21
AIC: -48.0810 Det(Omega_mle): 1.09708e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.382385 0.082863 4.615 0.000
L1.Burgenland 0.095231 0.044527 2.139 0.032
L1.Kärnten -0.116352 0.022838 -5.095 0.000
L1.Niederösterreich 0.166154 0.092354 1.799 0.072
L1.Oberösterreich 0.127635 0.093753 1.361 0.173
L1.Salzburg 0.281617 0.047789 5.893 0.000
L1.Steiermark 0.016671 0.061703 0.270 0.787
L1.Tirol 0.107705 0.049796 2.163 0.031
L1.Vorarlberg -0.085305 0.043860 -1.945 0.052
L1.Wien 0.031411 0.083824 0.375 0.708
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.029333 0.184059 0.159 0.873
L1.Burgenland -0.051290 0.098906 -0.519 0.604
L1.Kärnten 0.036430 0.050728 0.718 0.473
L1.Niederösterreich -0.224133 0.205140 -1.093 0.275
L1.Oberösterreich 0.475173 0.208249 2.282 0.023
L1.Salzburg 0.311114 0.106152 2.931 0.003
L1.Steiermark 0.099513 0.137058 0.726 0.468
L1.Tirol 0.307861 0.110609 2.783 0.005
L1.Vorarlberg 0.008669 0.097424 0.089 0.929
L1.Wien 0.018409 0.186194 0.099 0.921
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.233259 0.042158 5.533 0.000
L1.Burgenland 0.091037 0.022654 4.019 0.000
L1.Kärnten -0.004778 0.011619 -0.411 0.681
L1.Niederösterreich 0.220134 0.046987 4.685 0.000
L1.Oberösterreich 0.164693 0.047699 3.453 0.001
L1.Salzburg 0.035018 0.024314 1.440 0.150
L1.Steiermark 0.025558 0.031393 0.814 0.416
L1.Tirol 0.075348 0.025335 2.974 0.003
L1.Vorarlberg 0.056312 0.022315 2.524 0.012
L1.Wien 0.105268 0.042647 2.468 0.014
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171291 0.040999 4.178 0.000
L1.Burgenland 0.043621 0.022031 1.980 0.048
L1.Kärnten -0.012500 0.011300 -1.106 0.269
L1.Niederösterreich 0.147136 0.045695 3.220 0.001
L1.Oberösterreich 0.343463 0.046387 7.404 0.000
L1.Salzburg 0.098668 0.023645 4.173 0.000
L1.Steiermark 0.107190 0.030529 3.511 0.000
L1.Tirol 0.085746 0.024638 3.480 0.001
L1.Vorarlberg 0.054230 0.021701 2.499 0.012
L1.Wien -0.038907 0.041475 -0.938 0.348
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174321 0.079193 2.201 0.028
L1.Burgenland -0.041170 0.042555 -0.967 0.333
L1.Kärnten -0.036531 0.021826 -1.674 0.094
L1.Niederösterreich 0.124285 0.088264 1.408 0.159
L1.Oberösterreich 0.183958 0.089602 2.053 0.040
L1.Salzburg 0.253203 0.045673 5.544 0.000
L1.Steiermark 0.072164 0.058971 1.224 0.221
L1.Tirol 0.130185 0.047591 2.736 0.006
L1.Vorarlberg 0.106200 0.041918 2.534 0.011
L1.Wien 0.037260 0.080112 0.465 0.642
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.081757 0.062751 1.303 0.193
L1.Burgenland 0.015563 0.033720 0.462 0.644
L1.Kärnten 0.051475 0.017295 2.976 0.003
L1.Niederösterreich 0.177171 0.069939 2.533 0.011
L1.Oberösterreich 0.338582 0.070999 4.769 0.000
L1.Salzburg 0.050152 0.036191 1.386 0.166
L1.Steiermark -0.006821 0.046727 -0.146 0.884
L1.Tirol 0.122757 0.037710 3.255 0.001
L1.Vorarlberg 0.058481 0.033215 1.761 0.078
L1.Wien 0.112685 0.063479 1.775 0.076
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174986 0.076275 2.294 0.022
L1.Burgenland 0.011592 0.040987 0.283 0.777
L1.Kärnten -0.061147 0.021022 -2.909 0.004
L1.Niederösterreich -0.115106 0.085012 -1.354 0.176
L1.Oberösterreich 0.231679 0.086300 2.685 0.007
L1.Salzburg 0.037063 0.043990 0.843 0.399
L1.Steiermark 0.264351 0.056798 4.654 0.000
L1.Tirol 0.489303 0.045837 10.675 0.000
L1.Vorarlberg 0.071365 0.040373 1.768 0.077
L1.Wien -0.100982 0.077160 -1.309 0.191
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.138460 0.084274 1.643 0.100
L1.Burgenland -0.012969 0.045286 -0.286 0.775
L1.Kärnten 0.064105 0.023227 2.760 0.006
L1.Niederösterreich 0.170622 0.093927 1.817 0.069
L1.Oberösterreich -0.074358 0.095350 -0.780 0.435
L1.Salzburg 0.222026 0.048604 4.568 0.000
L1.Steiermark 0.134776 0.062754 2.148 0.032
L1.Tirol 0.050300 0.050644 0.993 0.321
L1.Vorarlberg 0.142640 0.044607 3.198 0.001
L1.Wien 0.168138 0.085252 1.972 0.049
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.459837 0.046524 9.884 0.000
L1.Burgenland -0.000735 0.025000 -0.029 0.977
L1.Kärnten -0.013192 0.012823 -1.029 0.304
L1.Niederösterreich 0.176822 0.051853 3.410 0.001
L1.Oberösterreich 0.266635 0.052639 5.065 0.000
L1.Salzburg 0.018506 0.026832 0.690 0.490
L1.Steiermark -0.014447 0.034644 -0.417 0.677
L1.Tirol 0.069064 0.027959 2.470 0.014
L1.Vorarlberg 0.056504 0.024626 2.295 0.022
L1.Wien -0.017096 0.047064 -0.363 0.716
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.025841 0.089553 0.153133 0.137448 0.062562 0.081844 0.015470 0.207254
Kärnten 0.025841 1.000000 -0.037966 0.126714 0.047051 0.072863 0.456318 -0.082193 0.093834
Niederösterreich 0.089553 -0.037966 1.000000 0.274687 0.095210 0.252539 0.050539 0.141555 0.243037
Oberösterreich 0.153133 0.126714 0.274687 1.000000 0.187893 0.284489 0.161060 0.125231 0.176255
Salzburg 0.137448 0.047051 0.095210 0.187893 1.000000 0.120002 0.060466 0.109530 0.061395
Steiermark 0.062562 0.072863 0.252539 0.284489 0.120002 1.000000 0.132056 0.087734 0.004390
Tirol 0.081844 0.456318 0.050539 0.161060 0.060466 0.132056 1.000000 0.063092 0.128273
Vorarlberg 0.015470 -0.082193 0.141555 0.125231 0.109530 0.087734 0.063092 1.000000 -0.011549
Wien 0.207254 0.093834 0.243037 0.176255 0.061395 0.004390 0.128273 -0.011549 1.000000